﻿using System;

using Moe.ECamel.Common.Entities;
using Moe.ECamel.Client.Controllers;
using Moe.ECamel.Client.WinForms.Common;

namespace Moe.ECamel.Client.WinForms.Controls
{
	public partial class CustomerDetailsControl : ECamelUserControl
	{
		public CustomerDetailsControl()
		{
			InitializeComponent();
		}

		public void Initialize(Customer customer, DetailsMode detailsMode)
		{
			this.UserDetailsControl.DetailsMode = detailsMode;

			Bind(customer);
		}

		private void Bind(Customer entity)
		{
			this.CustomerBindingSource.DataSource = entity;
			UserDetailsControl.Bind(entity.User);
		}

		public void RefreshBinding()
		{
			this.CustomerBindingSource.CurrencyManager.Refresh();
		}
		public void CancelEdit()
		{
			this.CustomerBindingSource.CancelEdit();
			this.UserDetailsControl.CancelEdit();
		}
	}
}